#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <Includes.h>
#include <utility.h>
#include <DRV_Event.h>
//#include <DRV_Bc28.h>
#include <DRV_EC600S.h>
#include <DRV_EC600S_Event.h>
#include <OPP_Debug.h>
#include <SVS_Para.h>

//注册到事件处理模块的调用函数
int EC600S_QPOWD_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret = Ec600sAT_QPOWD();
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_CMD_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret;
    ST_AT_EXE_OUT_DATA odata={0};

    rspArgv[0] = (char *)malloc(NEUL_MAX_BUF_SIZE);
    if(NULL == rspArgv[0]){
        return 1;
    }
    memset(rspArgv[0],0,NEUL_MAX_BUF_SIZE);
    odata.raw_data=rspArgv[0];
    ret = AtExe(EN_DEV_TYPE_EC600S,reqArgv[0],atoi(reqArgv[1]),NULL,&odata);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_CGSN_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    neul_dev_info_t info;
    char imei[NEUL_IMEI_LEN]={0};
    int ret=0;
    unsigned int len=NEUL_IMEI_LEN;

    Ec600sDevInfoGet(&info);
    //没缓存IMEI,通过AT指令获取IMEI
    if(0==strlen((char *)info.imei))
    {
        ret=Ec600sAT_CGSN(imei);
        if(ret!=0)
        {
            //noted by wangtao
            ret=AppParaRead(APS_PARA_MODULE_APS_EC600S, EC600S_IMEI_ID, (unsigned char *)imei, &len);
        }
    }
    else
    {
        strcpy(imei,(char *)info.imei);
    }

    rspArgv[0] = (char *)malloc(NEUL_IMEI_LEN);
    if(NULL == rspArgv[0]){
        return 1;
    }
    strcpy(rspArgv[0],imei);
    *retCode = ret;
    *rspArgc = 1;
    return 0;

}

int EC600S_CIMI_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    neul_dev_info_t info;
    char imsi[NEUL_IMSI_LEN]={0};
    int ret=0;

    Ec600sDevInfoGet(&info);
    //没缓存IMEI,通过AT指令获取IMEI
    if(0==strlen((char *)info.imsi))
    {
        ret=Ec600sAT_CIMI(imsi);
    }
    else
    {
        strcpy(imsi,(char *)info.imsi);
    }

    rspArgv[0] = (char *)malloc(NEUL_IMSI_LEN);
    if(NULL == rspArgv[0]){
        return 1;
    }
    strcpy(rspArgv[0],imsi);
    *retCode = ret;
    *rspArgc = 1;
    return 0;

}

int EC600S_QCCID_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    neul_dev_info_t info;
    char nccid[NEUL_NCCID_LEN]={0};
    int ret=0;

    Ec600sDevInfoGet(&info);
    //没缓存IMEI,通过AT指令获取IMEI
    if(0==strlen((char *)info.nccid))
    {
        ret=Ec600sAT_QCCID(nccid);
    }
    else
    {
        strcpy(nccid,(char *)info.nccid);
    }

    rspArgv[0] = (char *)malloc(NEUL_NCCID_LEN);
    if(NULL == rspArgv[0]){
        return 1;
    }
    strcpy(rspArgv[0],nccid);
    *retCode = ret;
    *rspArgc = 1;
    return 0;

}

int EC600S_ATI_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;

    rspArgv[0] = (char *)malloc(NEUL_MANUFACT_LEN);
    if(NULL == rspArgv[0]){
        return 1;
    }
    ret = Ec600sATI(rspArgv[0]);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_GMR_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;

    rspArgv[0] = (char *)malloc(NEUL_VER_LEN);
    if(NULL == rspArgv[0]){
        return 1;
    }
    ret = Ec600sAT_GMR(rspArgv[0]);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_QENG_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;

    rspArgv[0] = (char *)malloc(sizeof(ST_QENG));
    if(NULL == rspArgv[0]){
        return 1;
    }
    ret = Ec600sAT_QENG(rspArgv[0]);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_QCFG_NWSCANMODE_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;

    ret = Ec600sAT_QCFG_nwscanmode(atoi(reqArgv[0]),NULL);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_COPS_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;

    rspArgv[0] = (char *)malloc(sizeof(ST_COPS));
    if(NULL == rspArgv[0]){
        return 1;
    }
    ret = Ec600sAT_COPS(rspArgv[0]);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_CSQ_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;

    rspArgv[0] = (char *)malloc(sizeof(ST_CSQ));
    if(NULL == rspArgv[0]){
        return 1;
    }
    ret = Ec600sAT_CSQ(rspArgv[0]);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_CCLK_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;

    rspArgv[0] = (char *)malloc(sizeof(ST_TIME));
    if(NULL == rspArgv[0]){
        return 1;
    }
    ret = Ec600sAT_CCLK(rspArgv[0]);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_CGPADDR_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;

    rspArgv[0] = (char *)malloc(NEUL_IP_LEN);
    if(NULL == rspArgv[0]){
        return 1;
    }
    ret = Ec600sAT_CGPADDR(rspArgv[0]);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_CGMR_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;

    rspArgv[0] = (char *)malloc(NEUL_VER_LEN);
    if(NULL == rspArgv[0]){
        return 1;
    }
    ret = Ec600sAT_CGMR(rspArgv[0]);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_CGCONTRDP_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;

    rspArgv[0] = (char *)malloc(APN_NAME_LEN);
    if(NULL == rspArgv[0]){
        return 1;
    }
    ret = Ec600sAT_CGCONTRDP(rspArgv[0]);
    *retCode = ret;
    *rspArgc = 1;
    return 0;
}

int EC600S_SOCK_OPEN_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;
    int sock,sock_type;
    EC600S_ADDR to_addr,local_addr;

    ret=sscanf(reqArgv[0],"%d,%d,%[^,],%hd,%[^,],%hd",&sock,&sock_type,to_addr.dstAddr,&to_addr.port,local_addr.dstAddr,&local_addr.port);
    if(ret!=6)
    {
        *retCode = 1;
        *rspArgc = 0;
        return 10;
    }
    ret=Ec600sAT_QIOPEN(sock,(EN_SOCK_TYPE)sock_type,&to_addr,&local_addr);
    if(ret!=0)
        ret+=10;
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_SOCK_CLOSE_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;
    ret=Ec600sAT_QICLOSE(atoi(reqArgv[0]));
    if(ret!=0)
        ret+=10;
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

//1.busy,2.mtu is too big
int EC600S_SOCK_SEND_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;
    ret=Ec600sDataSend(atoi(reqArgv[0]),EN_DATA_TYPE_STR,(U8 *)reqArgv[1],atoi(reqArgv[2]));
    if(ret!=0)
        ret+=10;
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

//1.busy,2.mtu is too big
int EC600S_SOCK_SENDEX_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret=0;
    ret=Ec600sDataSend(atoi(reqArgv[0]),EN_DATA_TYPE_HEX,(U8 *)reqArgv[1],atoi(reqArgv[2]));
    if(ret!=0)
        ret+=10;
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_FASTCONN_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret;
    ret=Ec600sAT_FASTCONN((ST_FASTCONN_EVENT_PARA *)reqArgv[0]);
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_QMTCFG_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret;
    ret=Ec600sAT_QMTCFG((ST_QMTCFG_EVENT_PARA *)reqArgv[0]);
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_QMTOPEN_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret;
    ret=Ec600sAT_QMTOPEN((ST_QMTOPEN_EVENT_PARA *)reqArgv[0]);
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_QMTCLOSE_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret;
    ret=Ec600sAT_QMTCLOSE((ST_QMTCLOSE_EVENT_PARA *)reqArgv[0]);
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_QMTCONN_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret;
    ret=Ec600sAT_QMTCONN((ST_QMTCONN_EVENT_PARA *)reqArgv[0]);
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_QMTDISC_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret;
    ret=Ec600sAT_QMTDISC((ST_QMTDISC_EVENT_PARA *)reqArgv[0]);
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_QMTSUB_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret;
    ret=Ec600sAT_QMTSUB((ST_QMTSUB_EVENT_PARA *)reqArgv[0]);
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_QMTUNS_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret;
    ret=Ec600sAT_QMTUNS((ST_QMTUNS_EVENT_PARA *)reqArgv[0]);
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

int EC600S_QMTPUBEX_EVENT_Func(int reqArgc, char *reqArgv[], int *retCode,int *rspArgc,char *rspArgv[])
{
    int ret;
    ret=Ec600sAT_QMTPUBEX((ST_QMTPUBEX_EVENT_PARA *)reqArgv[0]);
    *retCode = ret;
    *rspArgc = 0;
    return 0;
}

//外部查询事件接口函数
int EC600S_QPOWD_EVENT_DO(int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QPOWD_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QPOWD_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}

    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_CMD_EVENT_DO(char *atcmd, char *rspcmd, int ato, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	sArgv[0] = (char *)malloc(1024);
	if(NULL == sArgv[0]){
		return 1;
	}
	memset(sArgv[0],0,1024);
	strncpy(sArgv[0],atcmd,strlen(atcmd));

	sArgv[1] = (char *)malloc(10);
	if(NULL == sArgv[1]){
        free(sArgv[0]);
		return 1;
	}
	memset(sArgv[1],0,10);
	itoa(ato,sArgv[1],10);
	sArgc = 2;
	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_CMD_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_CMD_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
		ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    strcpy(rspcmd,rArgv[0]);
	ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_CGSN_EVENT_DO(char *imei, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_CGSN_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_CGSN_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    strcpy(imei,rArgv[0]);
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_CIMI_EVENT_DO(char *imsi, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_CIMI_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_CIMI_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    strcpy(imsi,rArgv[0]);
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_QCCID_EVENT_DO(char *iccid, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QCCID_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QCCID_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    strcpy(iccid,rArgv[0]);
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_ATI_EVENT_DO(char *pid, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_ATI_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_ATI_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    strcpy(pid,rArgv[0]);
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_GMR_EVENT_DO(char *ver, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_GMR_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_GMR_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    strcpy(ver,rArgv[0]);
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_QENG_EVENT_DO(ST_QENG *qeng, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QENG_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QENG_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    memcpy(qeng,rArgv[0],sizeof(ST_QENG));
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_QCFG_NWSCANMODE_EVENT_DO(int scanmode, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	sArgv[0] = (char *)malloc(10);
	if(NULL == sArgv[0]){
		return 1;
	}
	memset(sArgv[0],0,10);
	itoa(scanmode,sArgv[0],10);
    sArgc=1;
	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QCFG_NWSCANMODE_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QCFG_NWSCANMODE_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_COPS_EVENT_DO(ST_COPS *cops, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_COPS_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_COPS_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    memcpy(cops,rArgv[0],sizeof(ST_COPS));
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_CSQ_EVENT_DO(ST_CSQ *csq, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_CSQ_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_CSQ_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    memcpy(csq,rArgv[0],sizeof(ST_CSQ));
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_CCLK_EVENT_DO(ST_TIME *time, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_CCLK_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_CCLK_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    memcpy(time,rArgv[0],sizeof(ST_TIME));
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_CGPADDR_EVENT_DO(char *ip, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_CGPADDR_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_CGPADDR_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    memcpy(ip,rArgv[0],NEUL_IP_LEN);
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_CGMR_EVENT_DO(char *ver, int timeout)
{
    int ret;
    char *sArgv[MAX_ARGC];
    char *rArgv[MAX_ARGC];
    int sArgc = 0, rArgc = 0;

    ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_CGMR_EVENT,RISE_STATE,sArgc,sArgv);
    ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_CGMR_EVENT,&rArgc,rArgv,timeout);
    if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
        return ret;
    }
    memcpy(ver,rArgv[0],NEUL_VER_LEN);
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_CGCONTRDP_EVENT_DO(char *apn, int timeout)
{
    int ret;
    char *sArgv[MAX_ARGC];
    char *rArgv[MAX_ARGC];
    int sArgc = 0, rArgc = 0;

    ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_CGCONTRDP_EVENT,RISE_STATE,sArgc,sArgv);
    ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_CGCONTRDP_EVENT,&rArgc,rArgv,timeout);
    if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
        return ret;
    }
    memcpy(apn,rArgv[0],APN_NAME_LEN);
    ARGC_FREE(rArgc,rArgv);
    return 0;
}


int EC600S_SOCK_OPEN_EVENT_DO(int sock, EN_SOCK_TYPE sock_type, EC600S_ADDR *to_addr, EC600S_ADDR *local_addr, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(128);
    if(sArgv[0]==NULL)
        return 1;

    if(local_addr==NULL)
        snprintf(sArgv[0],128,"%d,%d,%s,%d,%s,%d",sock,sock_type,to_addr->dstAddr,to_addr->port, "0.0.0.0", 0);
    else
        snprintf(sArgv[0],128,"%d,%d,%s,%d,%s,%d",sock,sock_type,to_addr->dstAddr,to_addr->port, local_addr->dstAddr, local_addr->port);

	sArgc = 1;
	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_SOCK_OPEN_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_SOCK_OPEN_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_SOCK_CLOSE_EVENT_DO(int sock, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(10);
    if(sArgv[0]==NULL)
        return 1;

	itoa(sock,sArgv[0],10);
	sArgc = 1;
	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_SOCK_CLOSE_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_SOCK_CLOSE_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_SOCK_SEND_EVENT_DO(int sock, U8 *data, int len, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(10);
    if(sArgv[0]==NULL)
        return 1;
	itoa(sock,sArgv[0],10);

    sArgv[1]=malloc(len);
    if(sArgv[1]==NULL)
        return 1;
    memcpy(sArgv[1],data,len);

    sArgv[2]=malloc(10);
    if(sArgv[2]==NULL)
        return 1;
	itoa(len,sArgv[2],10);
	sArgc = 3;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_SOCK_SEND_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_SOCK_SEND_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;

}

int EC600S_SOCK_SENDEX_EVENT_DO(int sock, U8 *data, int len, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(10);
    if(sArgv[0]==NULL)
        return 1;
	itoa(sock,sArgv[0],10);

    sArgv[1]=malloc(len);
    if(sArgv[1]==NULL)
        return 1;
    memcpy(sArgv[1],data,len);

    sArgv[2]=malloc(10);
    if(sArgv[2]==NULL)
        return 1;
	itoa(len,sArgv[2],10);
	sArgc = 3;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_SOCK_SENDEX_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_SOCK_SENDEX_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;

}

int EC600S_FASTCONN_EVENT_DO(ST_FASTCONN_EVENT_PARA *para, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(sizeof(ST_FASTCONN_EVENT_PARA));
    if(sArgv[0]==NULL)
        return 1;
    memcpy(sArgv[0],para,sizeof(ST_FASTCONN_EVENT_PARA));
	sArgc = 1;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_FASTCONN_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_FASTCONN_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;

}

int EC600S_QMTCFG_EVENT_DO(ST_QMTCFG_EVENT_PARA *para, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(sizeof(ST_QMTCFG_EVENT_PARA));
    if(sArgv[0]==NULL)
        return 1;
    memcpy(sArgv[0],para,sizeof(ST_QMTCFG_EVENT_PARA));
	sArgc = 1;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QMTCFG_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QMTCFG_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;

}


int EC600S_QMTOPEN_EVENT_DO(ST_QMTOPEN_EVENT_PARA *para, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(sizeof(ST_QMTOPEN_EVENT_PARA));
    if(sArgv[0]==NULL)
        return 1;
    memcpy(sArgv[0],para,sizeof(ST_QMTOPEN_EVENT_PARA));
	sArgc = 1;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QMTOPEN_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QMTOPEN_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;

}

int EC600S_QMTCLOSE_EVENT_DO(ST_QMTCLOSE_EVENT_PARA *para, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(sizeof(ST_QMTCLOSE_EVENT_PARA));
    if(sArgv[0]==NULL)
        return 1;
    memcpy(sArgv[0],para,sizeof(ST_QMTCLOSE_EVENT_PARA));
	sArgc = 1;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QMTCLOSE_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QMTCLOSE_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;

}


int EC600S_QMTCONN_EVENT_DO(ST_QMTCONN_EVENT_PARA *para, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(sizeof(ST_QMTCONN_EVENT_PARA));
    if(sArgv[0]==NULL)
        return 1;
    memcpy(sArgv[0],para,sizeof(ST_QMTCONN_EVENT_PARA));
	sArgc = 1;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QMTCONN_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QMTCONN_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_QMTDISC_EVENT_DO(ST_QMTDISC_EVENT_PARA *para, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(sizeof(ST_QMTDISC_EVENT_PARA));
    if(sArgv[0]==NULL)
        return 1;
    memcpy(sArgv[0],para,sizeof(ST_QMTDISC_EVENT_PARA));
	sArgc = 1;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QMTDISC_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QMTDISC_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;
}

int EC600S_QMTSUB_EVENT_DO(ST_QMTSUB_EVENT_PARA *para, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(sizeof(ST_QMTSUB_EVENT_PARA));
    if(sArgv[0]==NULL)
        return 1;
    memcpy(sArgv[0],para,sizeof(ST_QMTSUB_EVENT_PARA));
	sArgc = 1;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QMTSUB_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QMTSUB_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;

}

int EC600S_QMTUNS_EVENT_DO(ST_QMTUNS_EVENT_PARA *para, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(sizeof(ST_QMTUNS_EVENT_PARA));
    if(sArgv[0]==NULL)
        return 1;
    memcpy(sArgv[0],para,sizeof(ST_QMTUNS_EVENT_PARA));
	sArgc = 1;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QMTUNS_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QMTUNS_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;

}

int EC600S_QMTPUBEX_EVENT_DO(ST_QMTPUBEX_EVENT_PARA *para, int timeout)
{
	int ret;
	char *sArgv[MAX_ARGC];
	char *rArgv[MAX_ARGC];
	int sArgc = 0, rArgc = 0;

    sArgv[0]=malloc(sizeof(ST_QMTPUBEX_EVENT_PARA));
    if(sArgv[0]==NULL)
        return 1;
    memcpy(sArgv[0],para,sizeof(ST_QMTPUBEX_EVENT_PARA));
	sArgc = 1;

	ret = SendEvent(EN_DEV_TYPE_EC600S,EC600S_QMTPUBEX_EVENT,RISE_STATE,sArgc,sArgv);
	ret = RecvEvent(EN_DEV_TYPE_EC600S,EC600S_QMTPUBEX_EVENT,&rArgc,rArgv,timeout);
	if(0 != ret){
        ARGC_FREE(rArgc,rArgv);
		return ret;
	}
    ARGC_FREE(rArgc,rArgv);
    return 0;

}

